//
//  LZHudTool.swift
//  halikaPeso
//
//  Created by L-zh on 2024/12/18.
//

import MBProgressHUD

class LZHudTool {
    static func showMessage(message:String?) {
        self.showMessage(message: message, toView: nil)
    }
    
    static func showMessage(message:String?,toView:UIView?) {
        var view = toView
        if view == nil {
            view = UIApplication.shared.windows.last
        }
        let hud = MBProgressHUD.showAdded(to: view!, animated: true)
        hud.mode = MBProgressHUDMode.text;
        hud.label.text = message
        hud.label.textColor = UIColor.white
        hud.label.font = APPFont(f: 34)
        hud.bezelView.backgroundColor  = UIColor.black
        hud.customView?.backgroundColor = UIColor.black
        hud.removeFromSuperViewOnHide = true
        hud.hide(animated: true, afterDelay: 1.0)
    }
    
    static func showLoading() {
        self.showLoading(message: "加载中..")
    }
    
    static func showLoading(message:String?) {
        self.showLoading(message: message, toView: nil)
    }
    
    static func showLoading(message:String?,toView:UIView?) {
        var view = toView
        if view == nil {
            view = UIApplication.shared.windows.last
        }
        let hud = MBProgressHUD.showAdded(to: view!, animated: true)
        hud.mode = MBProgressHUDMode.indeterminate
        hud.label.text = message
        hud.label.textColor = UIColor.white
        hud.label.font = APPFont(f: 28)
        hud.contentColor = UIColor.white
        hud.bezelView.backgroundColor  = UIColor.black.withAlphaComponent(0.8)
        hud.removeFromSuperViewOnHide = true
        UIActivityIndicatorView.appearance(whenContainedInInstancesOf:
            [MBProgressHUD.self]).color = .white
    }
    
    static func dissmiss() {
       self.dissmiss(toView: nil)
    }
    
    static func dissmiss(toView:UIView?) {
        var view = toView
        if view == nil {
            view = UIApplication.shared.windows.last
        }
        MBProgressHUD.hide(for: view!, animated: true)
    }
}
